const path = require("path");
const Joi = require("@hapi/joi");
const handler = require(path.join(__dirname, "../services/analysisService.js"));
const { validate } = require("../middlewares/validate");

module.exports = (router, base) => {
  router.post(
    `/api/${base}/analysisClassify`,
    validate({
      payload: Joi.object().keys({
        type: Joi.string().required().description("分类类型"),
        userIds: Joi.array()
          .items(Joi.string())
          .optional()
          .description("用户id"),
        start: Joi.string().optional().description("开始日期"),
        end: Joi.string().optional().description("结束日期"),
      }),
    }),
    handler.analysisClassify
  );

  router.post(
    `/api/${base}/analysisDate`,
    validate({
      payload: Joi.object().keys({
        type: Joi.string().required().description("分类类型"),
        userIds: Joi.array()
          .items(Joi.string())
          .optional()
          .description("用户id"),
        start: Joi.string().optional().description("开始日期"),
        end: Joi.string().optional().description("结束日期"),
        range: Joi.string().allow('').optional().description("计算单位年/月/日"),
      }),
    }),
    handler.analysisDate
  );
};
